import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

// 导出一个路由实例
export default new Router({
  mode: 'history', // 默认是hash模式
  routes: [
    // 默认跳转：重定向
    {
      path: '/',
      redirect: '/product',
    },
    {
      path: '/product',
      component: () => import('@/views/product/index'),
      redirect: '/product/list',
      // 配置子路由
      children: [
        {
          path: 'list',
          component: () => import('@/views/product/children/list'),
        },
        {
          // 动态路由
          path: 'detail/:productId',
          component: () => import('@/views/product/children/detail'),
        },
      ],
    },
    {
      path: '/classify',
      component: () => import('@/views/classify/index'),
    },
    {
      path: '/cart',
      component: () => import('@/views/cart/index'),
    },
    {
      path: '/my',
      component: () => import('@/views/my/index'),
    },
    // 404配置
    {
      path: '*',
      component: () => import('@/components/NotFound'),
    },
    // demo配置
    {
      path: '/demo',
      component: () => import('@/components/Demo'),
    },
  ],
})
